/*
 * @Author: yeminglong
 * @Date: 2023-12-01 13:49:22
 * @LastEditTime: 2023-12-01 14:41:15
 * @LastEditors: yeminglong
 * @Description:
 */
import {defineConfig} from 'vite';
import vue from '@vitejs/plugin-vue';
import AutoImport from 'unplugin-auto-import/vite';
import Components from 'unplugin-vue-components/vite';
import {ElementPlusResolver} from 'unplugin-vue-components/resolvers';

// gzip压缩
import viteCompression from 'vite-plugin-compression';
// svgicon
import {createSvgIconsPlugin} from 'vite-plugin-svg-icons';
// jsx
import vueJsx from '@vitejs/plugin-vue-jsx';
import path from 'path';

import eslintPlugin from 'vite-plugin-eslint';
// https://vitejs.dev/config/
export default defineConfig({
	plugins: [
		vue(),
		vueJsx(),
		eslintPlugin({
			include: ['src/**/*.ts', 'src/**/*.vue'],
		}),
		viteCompression({
			threshold: 1024000 / 2, // 对大于 1mb 的文件进行压缩
		}),

		AutoImport({
			imports: ['vue', 'vue-router'],
			resolvers: [ElementPlusResolver()],
		}),
		Components({
			resolvers: [ElementPlusResolver()],
		}),
		createSvgIconsPlugin({
			// 指定需要缓存的图标文件夹
			iconDirs: [path.resolve(process.cwd(), 'src/assets/icons')],
			// 指定symbolId格式
			symbolId: 'icon-[dir]-[name]',

			/**
             * 自定义插入位置
             * @default: body-last
             */
			// inject?: 'body-last' | 'body-first'

			/**
             * custom dom id
             * @default: __svg__icons__dom__
             */
			// customDomId: '__svg__icons__dom__',
		}),
	],
	resolve: {
		// 配置路径别名
		alias: {
			'@': '/src',
		},
	},
	base: './',
	//打包配置
	build: {
		//传递给 Terser 的更多 minify 选项。 生产环境去除 console debugger
		terserOptions: {
			compress: {
				drop_console: true,
				drop_debugger: true,
			},
		},
	},
});
